# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=eresi
pkgver=1291.4769c175
pkgrel=3
pkgdesc='The ERESI Reverse Engineering Software Interface.'
groups=('blackarch' 'blackarch-binary' 'blackarch-reversing'
        'blackarch-debugger' 'blackarch-disassembler')
arch=('x86_64' 'aarch64')
url='https://github.com/thorkill/eresi'
license=('GPL2')
depends=('openssl')
makedepends=('git')
optdepends=('linux-headers' 'linux-lts-headers' 'linux-hardened-headers'
            'linux-rt-headers' 'linux-rt-lts-headers' 'linux-zen-headers')
source=("git+https://github.com/thorkill/$pkgname.git"
        'stabs-trans.c.patch'
        'dwarf2-trans.c.patch')
sha512sums=('SKIP'
            '6a36c0a8e1af4f594cafa6cbffbd848e900bdf944bd1193965bcf24e27eaa2e3b868c6d57d14dd8c8b9652f152cd5c47c6a431751c2ccd932e446e17e6abe87e'
            '300ce90bf54138313a0318303553b918c8300350e52e16b41a77bcb7a305192d3ae1b395904a113df91beeed097b064ae599dad47e208eb6925f0fbf210d7593')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  patch -p2 < "$srcdir/dwarf2-trans.c.patch"
  patch -p2 < "$srcdir/stabs-trans.c.patch"
}

build() {
  cd $pkgname

  export DESTDIR="$pkgdir/usr"

  ./configure --enable-32-64

  make
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/lib"

  make DESTDIR="$pkgdir/usr" install

  install -Dm 644 doc/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm doc/LICENSE

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.FIRST doc/*

  rm "$pkgdir/usr/bin/"{e2dbg,elfsh,eresi-config,etrace,evarista,kedbg}
}

